package com.taysear.dbservice.resources;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;



public class DbHelper 
{
	public static ResultSet executeSelect(Connection pCn,String pSqlQuery)throws Exception
	{		
		try
		{			
			PreparedStatement vQueryStm = pCn.prepareStatement(pSqlQuery);
			ResultSet rs = vQueryStm.executeQuery();
			
			return rs;
		}
		catch(Exception e)
		{
			throw new Exception("#executeScalar, Qry: "+pSqlQuery+", "+e.getMessage());
		}	
	}
	public static int executeUpdate(Connection pCn,String pSqlQuery)throws Exception
	{		
		try
		{			
			PreparedStatement vQueryStm = pCn.prepareStatement(pSqlQuery);
			return  vQueryStm.executeUpdate();			
		}
		catch(Exception e)
		{
			throw new Exception("#executeScalar, Qry: "+pSqlQuery+", "+e.getMessage());
		}	
	}
	public static Object executeScalar(Connection pCn, String pSqlQuery)throws Exception
	{		
		try
		{		
			Object vObj=null;
			ResultSet rs=null;
			PreparedStatement vQueryStm = pCn.prepareStatement(pSqlQuery);
			rs = vQueryStm.executeQuery();
			if(rs!=null)				
			{
				if(rs.next())
					vObj=rs.getObject(1);
			}
			return vObj;
		}
		catch(Exception e)
		{
			throw new Exception("#executeScalar, Qry: "+pSqlQuery+", "+e.getMessage());
		}	
	}


}
